package com.gexin.model.config;

import com.gexin.common.utils.SQLUtils;
import com.gexin.model.config.base.BaseAdvertising;
import com.jfinal.plugin.activerecord.Page;

import java.util.LinkedList;
import java.util.List;

/**
 * 业务名称:  t_advertising(广告位) 
 */
@SuppressWarnings("serial")
public class Advertising extends BaseAdvertising<Advertising> {
	public static final Advertising dao = new Advertising();

	public Page<Advertising> query(int pageNumber,int pageSize,Advertising ad){
		List<Object> list =new LinkedList<>();
		SQLUtils sql=new SQLUtils(" from t_advertising a left join t_products p on a.product_id = p.id  where 1=1 ");
		if(ad!=null){
			if(ad.getStatus()!=null){
				sql.append(" and a.status = ? ");
				list.add(ad.getStatus());
			}
			if(ad.getProductId()!=null){
				sql.append(" and a.product_id = ? ");
				list.add(ad.getProductId());
			}
		}
		sql.append(" order by a.sort desc,a.create_time desc ");
		return paginate(pageNumber,pageSize,"select a.*,p.product_name ",sql.toString(),list.toArray());
	}

}
